home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------
- BOXES2.C -- OS/2 PM program that draws nested boxes in client window
- (c) 1988, Ziff Communications Company
- PC Magazine * Charles Petzold, 4/88
- ----------------------------------------------------------------------*/
-
- #define INCL_WIN
- #include <os2.h>
- #include <stddef.h>
- #include "boxes2.h"
-
- #define NUMBOXES 50 /* number of boxes to draw */
- #define INCREMENT 20 /* rotate each 1/20th of side */
-
- MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
-
- int main (void)
- {
- static CHAR szClientClass [] = "Boxes2" ;
- HAB hab ;
- HMQ hmq ;
- HWND hwndFrame, hwndClient ;
- QMSG qmsg ;
-
- hab = WinInitialize (0) ;
- hmq = WinCreateMsgQueue (hab, 0) ;
-
- WinRegisterClass (
- hab, /* Anchor block handle */
- szClientClass, /* Name of class being registered */
- ClientWndProc, /* Window procedure for class */
- CS_SIZEREDRAW, /* Class style */
- 0) ; /* Extra bytes to reserve */
-
- hwndFrame = WinCreateStdWindow (
- HWND_DESKTOP, /* Parent window handle */
- WS_VISIBLE /* Style of frame window */
- | FS_SIZEBORDER
- | FS_TITLEBAR
- | FS_SYSMENU
- | FS_MINMAX
- | FS_MENU,
- szClientClass, /* Client window class name */
- szClientClass, /* Title bar text */
- 0L, /* Style of client window */
- NULL, /* Module handle for resources */
- ID_MAINMENU, /* ID of resources */
- &hwndClient) ; /* Pointer to client window handle */
-
- while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
- WinDispatchMsg (hab, &qmsg) ;
-
- WinDestroyWindow (hwndFrame) ;
- WinDestroyMsgQueue (hmq) ;
- WinTerminate (hab) ;
-
- return 0 ;
- }
-
- MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
- {
- static LONG alColors [] = { CLR_BLACK, CLR_BLUE, CLR_RED, CLR_PINK,
- CLR_GREEN, CLR_CYAN, CLR_YELLOW, CLR_WHITE,
- CLR_DARKGRAY, CLR_DARKBLUE, CLR_DARKRED,
- CLR_DARKPINK, CLR_DARKGREEN, CLR_DARKCYAN,
- CLR_BROWN, CLR_LIGHTGRAY } ;
-
- static SHORT xClient, yClient, idBackground = IDM_BACKGROUND + 7,
- idForeground = IDM_FOREGROUND ;
- HPS hps;
- HWND hwndMenu ;
- POINTL aptl[5] ;
- SHORT sRep, sSide ;
-
- switch (msg)
- {
- case WM_COMMAND:
-
- hwndMenu = WinWindowFromID (
- WinQueryWindow (hwnd, QW_PARENT, FALSE),
- FID_MENU) ;
-
- if (COMMANDMSG(&msg)->cmd >= IDM_BACKGROUND &&
- COMMANDMSG(&msg)->cmd <= IDM_BACKGROUND + 15)
- {
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (idBackground, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0)) ;
-
- idBackground = COMMANDMSG(&msg)->cmd ;
-
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (idBackground, TRUE),
- MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED)) ;
- }
-
- else if (COMMANDMSG(&msg)->cmd >= IDM_FOREGROUND &&
- COMMANDMSG(&msg)->cmd <= IDM_FOREGROUND + 15)
- {
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (idForeground, TRUE),
- MPFROM2SHORT (MIA_CHECKED, 0)) ;
-
- idForeground = COMMANDMSG(&msg)->cmd ;
-
- WinSendMsg (hwndMenu, MM_SETITEMATTR,
- MPFROM2SHORT (idForeground, TRUE),
- MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED)) ;
- }
- else
- break ;
-
- WinInvalidateRect (hwnd, NULL, FALSE) ;
- break ;
-
- case WM_SIZE:
- xClient = SHORT1FROMMP (mp2) ;
- yClient = SHORT2FROMMP (mp2) ;
- break ;
-
- case WM_PAINT:
- hps = WinBeginPaint (hwnd, NULL, NULL) ;
-
- aptl[0].x = aptl[1].x = 0 ;
- aptl[2].x = aptl[3].x = xClient - 1 ;
- aptl[0].y = aptl[3].y = 0 ;
- aptl[1].y = aptl[2].y = yClient - 1 ;
-
- GpiSetColor (hps, alColors[idBackground - IDM_BACKGROUND]) ;
-
- GpiMove (hps, aptl) ;
- GpiBox (hps, DRO_FILL, aptl + 2, 0L, 0L) ;
-
- GpiSetColor (hps, alColors[idForeground - IDM_FOREGROUND]) ;
-
- for (sRep = 0 ; sRep < NUMBOXES ; sRep ++)
- {
- aptl[4] = aptl[0] ;
-
- GpiMove (hps, aptl) ;
- GpiPolyLine (hps, 4L, aptl + 1) ;
-
- for (sSide = 0 ; sSide < 4 ; sSide++)
- {
- aptl[sSide].x = ((INCREMENT - 1) * aptl[sSide].x +
- aptl[sSide + 1].x +
- INCREMENT / 2) / INCREMENT ;
-
- aptl[sSide].y = ((INCREMENT - 1) * aptl[sSide].y +
- aptl[sSide + 1].y +
- INCREMENT / 2) / INCREMENT ;
- }
- }
- WinEndPaint (hps) ;
- break ;
-
- default:
- return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
- }
- return FALSE ;
- }